package com.application.fragment;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Toast;

import com.application.R;


public class StaticFragment extends Fragment {
    private TextView tvLike;
    private RadioButton rbLike,rbDislike;
    private RatingBar rbStar;


    public StaticFragment() {
    }


    public static StaticFragment newInstance() {
        return new StaticFragment();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_static, container, false);
    }
    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        tvLike=view.findViewById(R.id.tv_like);
        rbLike=view.findViewById(R.id.rb_like);
        rbDislike=view.findViewById(R.id.rb_dislike);
        rbStar=view.findViewById(R.id.rb_star);

        rbLike.setOnCheckedChangeListener((buttonView, isChecked) -> {
            if (isChecked){
                tvLike.setText("app:喜欢");
            }
        });
        rbDislike.setOnCheckedChangeListener((buttonView, isChecked) -> {
            if (isChecked){
                tvLike.setText("app:不喜欢");
            }
        });
        rbStar.setOnRatingBarChangeListener((ratingBar, rating, fromUser) -> {
            if (fromUser){
                Toast.makeText(getActivity(),"点了"+rating,Toast.LENGTH_SHORT).show();
            }
        });
    }
}